package com.example.redisdemo01.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * @date 2023/7/25 23:45
 */
@RestController
public class RedisController {

    // 引入 redis 模板 (redis 本身)
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @RequestMapping("/set")
    public String setRedis() {
        // 操作 Redis 的 String 类型
        stringRedisTemplate.opsForValue().set("username", "xiaohuang");
        return "redis 存储成功";
    }

    @RequestMapping("/get")
    public String getRedis() {
        String result = stringRedisTemplate.opsForValue().get("username");
        return result;
    }

}
